package com.momosw.games.engine.player;

import java.util.LinkedList;
import java.util.List;

import com.momosw.games.engine.Action;
import com.momosw.games.engine.EndTurnAction;
import com.momosw.games.engine.Game;
import com.momosw.games.engine.Option;
import com.momosw.games.engine.Turn;
import com.momosw.games.engine.events.Event;
import com.momosw.games.jericho.board.Card;

/**
 * A Player has a name and a set of cards that can play during his turn.
 * 
 * <b>Project:</b> JerichoCardGame<br />
 * <b>Package:</b> com.momosw.games.engine.player<br />
 * <b>Class:</b> Player.java<br />
 * <br />
 * <i>GSI 2011</i><br />
 *
 * @author Miguel Coronado (miguelcb84@gmail.com)
 * @version	Aug 23, 2011
 *
 */
public abstract class Player {

    /** The name of the player */
    private String name;
    /** The cards in player's hand */
    private List<Card> hand;
    
    /**
     * Constructor.
     * @param name
     */
    public Player (String name) {
        this.name = name;
        this.hand = new LinkedList<Card>();
    }
    
    /** 
     * Get the name of the Player
     * @return the Name of the player
     */
    public String getName() {
        return name;
    }

    /** 
     * Publish a message in the display if the player
     * @param string
     */
    public abstract void notify(String string);
    
    /**
     * 
     * @param event
     */
    public abstract void notify(Event event);
    
    /**
     * Choose between a set of options. These might be <code>Action</code>s, 
     * <code>Card</code>s or <code>WallType<code>s.
     * 
     * @param options   
     * @return          
     */
    public abstract Option chooseBetween(List<? extends Option> options);
    
    /**
     * 
     * @param game
     * @param turn
     */
    public void takeTurn(Game game, Turn turn) {
        Action action = null;
        do{
            List<Action> actions = turn.availableActions (this);
            action = (Action) chooseBetween (actions);
            turn.execute (action, this);
            turn.doAction(action);
        }
        while(!(action instanceof EndTurnAction));
    }

    @Override
    public String toString() {
        return name;
    }

    public void addToHand(Card drawCard) {
        this.hand.add(drawCard);
    }

    public List<Card> getHand() {
        return this.hand;
    }

    public boolean removeFromHand(Card card) {
        return this.hand.remove(card);
    }
    
    public void clearHand() {
        this.hand = new LinkedList<Card>();
    }
}
